$("#companyDiv").hide();
var content = null;
function openCompany(){
	$("#companyDiv").show();
	$("#companyUrl").empty();
}

function closeCompany(){
	$("#companyDiv").hide();
	$("#companyUrl").empty();
}

function setContent(userid){
	$.ajax({
		url: Global.common.newUrl + "UserTypeController/getVipById?id=" + userid,
		type: "get",
		dataType: "json",		
		success: function(result){			
			if(result.isSuccess){
				openCompany();
				var data = result.data;
				if( data.length > 0){
					setVipUser(data[0]);
				}else{
					$.ajax({
						url: Global.common.newUrl + "UserTypeController/getUserById?id=" + userid,
						type: "get",
						dataType: "json",		
						success: function(result){
							setNormalUser(result.data);
						}				
					});	
				}
			}											   
		},
		error:function(){
			console.log("查询用户详细信息失败");
		}			
	});
}
/** 
 *  VIP用户 
 * 
*/
function setVipUser(data){
			$("#userName").text(data.name);
			var code ="";
			code += data.countyName !== null && data.countyName !== "" ? data.countyName :"";
			code += data.belongsTownship !== null && data.belongsTownship !== "" ? "-"+data.belongsTownship :"";
			code += data.areaCode !== null && data.areaCode !== "" ? "("+data.areaCode+")" :"";
			$("#userCode").text(code);
			$("#userType").text(data.type);				
			if( data.epath !== null && data.epath !== "" ){
				$("#companyUrl").append("<a href=\""+data.epath+"\" target=\"_blank\">电商平台</a>");
			}else{
				$("#companyUrl").append("<div>电商平台: 暂无数据</div>");
			}
			var content = document.querySelector("#content"),
				contentHtml = "";
				content.innerHTML = contentHtml;
			contentHtml	= "<div class=\"uldiv\">";
					if( data.businessScope !== null && data.businessScope !== "" ){
						contentHtml += "<li class=\"poplong\">经营范围: "+ data.businessScope + "</li>";
					} else{
						contentHtml += "<li class=\"poplong\">经营范围: </li>";
					}
					if( data.areaScale !== null && data.areaScale !== "" ){
						contentHtml += "<li class=\"popli\">面积/生产规模: "+ data.areaScale + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">面积/生产规模: </li>";
					}
					contentHtml += "</div>"+ 	
								   "<div class=\"uldiv\">";
					if( data.annualProductionValue !== null && data.annualProductionValue !== "" ){
						contentHtml += "<li class=\"popli\">年产值(万): "+ data.annualProductionValue + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">年产值(万): </li>";
					}
					if( data.prodOperaCount !== null && data.prodOperaCount !== "" ){
						contentHtml += "<li class=\"popli\">从事生产人数: "+ data.prodOperaCount + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">从事生产人数: </li>";
					}
					contentHtml += "</div>"+ 	
								   "<div class=\"uldiv\">";
					if( data.techCount !== null && data.techCount !== "" ){
						contentHtml += "<li class=\"popli\">技术人员: "+ data.techCount + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">技术人员: </li>";
					}
					if( data.techAverageAge !== null && data.techAverageAge !== "" ){
						contentHtml += "<li class=\"popli\">技术人员平均年龄: "+ data.techAverageAge + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">技术人员平均年龄: </li>";
					}
					contentHtml += "</div>"+ 	
								   "<div class=\"uldiv\">";
					if( data.netComputerAccess !== null && data.netComputerAccess !== "" ){
						contentHtml += "<li class=\"popli\">电脑联网: "+ data.netComputerAccess + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">电脑联网: </li>";
					}
					if( data.useSmartPhones !== null && data.useSmartPhones !== "" ){
						contentHtml += "<li class=\"popli\">使用智能手机: "+ data.useSmartPhones + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">使用智能手机: </li>";
					}
					contentHtml += "</div>"+ 	
								   "<div class=\"uldiv\">";
					if( data.smartPhoneBrand !== null && data.smartPhoneBrand !== "" ){
						contentHtml += "<li class=\"popli\">智能手机品牌: "+ data.smartPhoneBrand + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">智能手机品牌: </li>";
					}
					if( data.techLeaderName !== null && data.techLeaderName !== "" ){
						contentHtml += "<li class=popli>负责人: "+ data.techLeaderName + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">负责人: </li>";
					}
					contentHtml += "</div>"+ 	
								   "<div class=\"uldiv\">";
					if( data.techLeaderPhone !== null && data.techLeaderPhone !== "" ){
						contentHtml += "<li class=\"popli\">负责人电话: "+ data.techLeaderPhone + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">负责人电话: </li>";
					}
					if( data.leaderName !== null && data.leaderName !== "" ){
						contentHtml += "<li class=\"popli\">技术主管: "+ data.leaderName + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">技术主管: </li>";
					}
					contentHtml += "</div>"+ 	
								   "<div class=\"uldiv\">";
					if( data.techLeaderPhone !== null && data.techLeaderPhone !== "" ){
						contentHtml += "<li class=\"popli\">技术主管电话: "+ data.techLeaderPhone + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">技术主管电话: </li>";
					}
					contentHtml += "</div>"+ 	
								   "<div class=\"uldiv\">";
					if( data.intro !== null && data.intro !== "" ){
						contentHtml += "<li class=\"poplides\" title=\""+ data.intro +"\">介绍: "+ data.intro +"</li>"+
										"</div>";
					}else{
						contentHtml += "<li class=\"poplides\">介绍: 暂无数据</li>"+
										"</div>";
					}
			content.innerHTML = contentHtml;
}

/** 
 *  普通用户 
 * 
*/
function setNormalUser(data){
			$("#userName").text(data.username);
			var code ="";
			code += data.address !== null ? data.address :"";
			code += data.areaCode !== null ? "("+data.areaCode+")" :"";
			$("#userCode").text(code);
			$("#userType").text("");	
			$("#companyUrl").append("<div>暂无数据</div>");
			var content = document.querySelector("#content"),
				contentHtml = "";
				content.innerHTML = contentHtml;
			contentHtml	= "<div class=\"uldiv\">";
					if( data.mobile !== null && data.mobile !== ""){
						contentHtml += "<li class=\"popli\">负责人电话: "+ data.mobile + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">负责人电话: </li>";
					}
					if( data.email !== null && data.email !== ""){
						contentHtml += "<li class=\"popli\">邮箱: "+ data.email + "</li>";
					} else{
						contentHtml += "<li class=\"popli\">邮箱: 暂无数据</li>";
					}
					contentHtml += "</div>"+ 	
								   "<div class=\"uldiv\">";
					if( data.introduction !== null && data.introduction !== ""){
						contentHtml += "<li class=\"poplides\">介绍: "+ data.introduction + "</li>";
					} else{
						contentHtml += "<li class=\"poplides\">介绍: 暂无数据</li>";
					}
					contentHtml += "</div>";									   			   
			content.innerHTML = contentHtml;
}
//声明需要用到的变量
var mx = 0,my = 0;      //鼠标x、y轴坐标（相对于left，top）
var dx = 0,dy = 0;      //对话框坐标（同上）
var isDraging = false;  //不可拖动
//鼠标按下
$("#companyTitle").mousedown(function(e){
	e = e || window.event;
	mx = e.pageX;     //点击时鼠标X坐标
	my = e.pageY;     //点击时鼠标Y坐标
	dx = $("#companyDiv").offset().left;
	dy = $("#companyDiv").offset().top;
	isDraging = true;      //标记对话框可拖动                
});

//鼠标移动更新窗口位置
$(document).mousemove(function(e){
	var e = e || window.event;
	var x = e.pageX;      //移动时鼠标X坐标
	var y = e.pageY;      //移动时鼠标Y坐标
	if(isDraging){        //判断对话框能否拖动
		var moveX = dx + x - mx;      //移动后对话框新的left值
		var moveY = dy + y - my;      //移动后对话框新的top值
		//设置拖动范围
		var pageW = $(window).width();
		var pageH = $(window).height();
		var dialogW = $("#companyDiv").width();
		var dialogH = $("#companyDiv").height();
		var maxX = pageW - dialogW;       //X轴可拖动最大值
		var maxY = pageH - dialogH;       //Y轴可拖动最大值
		moveX = Math.min(Math.max(0,moveX),maxX);     //X轴可拖动范围
		moveY = Math.min(Math.max(0,moveY),maxY);     //Y轴可拖动范围
		//重新设置对话框的left、top
		$("#companyDiv").css({"left":moveX + 'px',"top":moveY + 'px'});
	} else if(Global.common.imagetitleFlage){
		var moveX = dx + x - mx;
		var moveY = dy + y - my;      
		var pageW = $(window).width();
		var pageH = $(window).height();
		var dialogW = $("#datukuang").width();
		var dialogH = $("#datukuang").height();
		var maxX = pageW - dialogW;       
		var maxY = pageH - dialogH;       
		moveX = Math.min(Math.max(0,moveX),maxX);     
		moveY = Math.min(Math.max(0,moveY),maxY);     
		$("#datukuang").css({"left":moveX + 'px',"top":moveY + 'px'});
	}
});

//鼠标离开
$("#companyTitle").mouseup(function(){
	isDraging = false;
});